package com.honeycomb.action.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.honeycomb.action.BaseWebAction;
import com.honeycomb.service.IUserService;
import com.honeycomb.utils.SystemConstants;
import com.honeycomb.vo.BaseVO;
import com.honeycomb.vo.ResultDto;
import com.honeycomb.vo.UserInfoVO;
import com.honeycomb.vo.UserStatusVO;



/**
 * 
 * @author ZhongJiang
 *
 * @function 用户登出
 * 
 * @param loginUserEmail 用户登录session信息ID
 * 
 * @return String
 *
 *
 */
public class DoLoginOutAction extends BaseWebAction {

	private IUserService iUserService;
	
	public IUserService getiUserService() {
		return iUserService;
	}
	public void setiUserService(IUserService iUserService) {
		this.iUserService = iUserService;
	}

	@Override
	protected String doRequest(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) {
		logger.info("---------------DoLoginOutAction--------------");
		
		UserStatusVO userStatusVO = null;
		ResultDto<BaseVO> resultDtoUpdateLoginStatust = null;
		try {
			UserInfoVO loginUserInfoVO = (UserInfoVO)session.getAttribute(SystemConstants.HoneyComb_LoginUser_Session_Name);
			if(loginUserInfoVO != null) {
				session.removeAttribute(SystemConstants.HoneyComb_LoginUser_Session_Name);
				//作更新用户登录状态
				userStatusVO = new UserStatusVO();
				userStatusVO.setUserId(loginUserInfoVO.getUserId());
				resultDtoUpdateLoginStatust = this.getiUserService().doUpdateUserStatusToNotOnline(userStatusVO);
				if(!resultDtoUpdateLoginStatust.isSuccess()) {
					return "GlobalErrorPage";
				}
			}
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "GlobalErrorPage";
		}
	}

}
